//
// Created by Javery Chiang on 2025/5/4.
//

#include "Graph.h"


void Graph::DFS(int start) {
    unordered_set<int> visited;
    cout << "DFS 遍历：";
    DFSUtil(start, visited);
    cout << endl;
}

void Graph::BFS(int start) {
    unordered_set<int> visited;
    queue<int> q;

    cout << "BFS 遍历：";

    q.push(start);
    visited.insert(start);

    while (!q.empty()) {
        int current = q.front();
        q.pop();
        cout << current << " ";
        for (int neighbor: adj[current]) {
            if (visited.find(neighbor) == visited.end()) {
                visited.insert(neighbor);
                q.push(neighbor);
            }
        }
    }
    cout << endl;
}